// API 配置和服务
const API_BASE_URL = window.VUE_APP_API_BASE_URL || 'http://localhost:5000';

class ApiService {
  static async replaceStrings(originalFile, replaceFile) {
    const formData = new FormData();
    formData.append('original_file', originalFile);
    formData.append('replace_file', replaceFile);

    const response = await fetch(`${API_BASE_URL}/replace`, {
      method: 'POST',
      body: formData
    });

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(errorData.error || '处理失败');
    }

    return response.blob();
  }

  static async getBingWallpaper() {
    try {
      const response = await fetch(`${API_BASE_URL}/bing-wallpaper`);
      const data = await response.json();
      return data.url;
    } catch (error) {
      console.error('获取背景图片失败:', error);
      return 'https://via.placeholder.com/1920x1080/4285f4/ffffff?text=Replace+Strings+Tool';
    }
  }

  static async healthCheck() {
    try {
      const response = await fetch(`${API_BASE_URL}/health`);
      return await response.json();
    } catch (error) {
      console.error('健康检查失败:', error);
      return { status: 'error', message: '无法连接到服务器' };
    }
  }
}

export default ApiService;
